package nc.ui.cmp.cm;

import java.util.Vector;

import nc.ui.glpub.IUiPanel;
import nc.ui.glpub.UiManager;
import nc.ui.pub.FramePanel;
import nc.ui.pub.ILinkOperateable;
import nc.ui.pub.linkoperate.ILinkAdd;
import nc.ui.pub.linkoperate.ILinkAddData;
import nc.ui.pub.linkoperate.ILinkApprove;
import nc.ui.pub.linkoperate.ILinkApproveData;
import nc.ui.pub.linkoperate.ILinkMaintain;
import nc.ui.pub.linkoperate.ILinkMaintainData;
import nc.ui.pub.linkoperate.ILinkQuery;
import nc.ui.pub.linkoperate.ILinkQueryData;
import nc.ui.pub.tcgmsg.MsgManageUI;
import nc.vo.pub.msg.MessageVO;

public class UiManagerCmp2004 extends UiManager implements ILinkOperateable, ILinkApprove, ILinkQuery, ILinkAdd,ILinkMaintain{

	private static final long serialVersionUID = 4290750874731813590L;

	private MsgManageUI msgui = null;
	
	/**
     * @param panel
     */
    public UiManagerCmp2004(FramePanel panel) {
        super(panel);
    }
	public void initData(nc.vo.pub.msg.MessageVO msgvo) {
//	    nc.bs.logging.Log.getInstance(this.getClass()).warn("initData in manager invoked \n");
	    IUiPanel iPanel = this.getCurrentPanel();
	    if(iPanel instanceof BusiBillPanel){
//	        nc.bs.logging.Log.getInstance(this.getClass()).warn("stamp1");
	        BusiBillPanel djPanel = (BusiBillPanel)iPanel;
	        djPanel.postInit();
//	        djPanel.initData(msgvo);
//	        nc.bs.logging.Log.getInstance(this.getClass()).warn("stamp3");
	    }
	}
	public void doApproveAction(ILinkApproveData approvedata) {
		 IUiPanel iPanel = this.getCurrentPanel();
		    if(iPanel instanceof BusiBillPanel){
		        BusiBillPanel djPanel = (BusiBillPanel)iPanel;
		        djPanel.doApproveAction(approvedata);
		        
		        msgui = (MsgManageUI) approvedata.getUserObject();
		    }
	}

	public void doQueryAction(ILinkQueryData querydata) {
		 IUiPanel iPanel = this.getCurrentPanel();
		    if(iPanel instanceof BusiBillPanel){
		        BusiBillPanel djPanel = (BusiBillPanel)iPanel;
		        djPanel.doQueryAction(querydata);
		    }
	}

 
	public void doAddAction(ILinkAddData adddata) {
		IUiPanel iPanel = this.getCurrentPanel();
	    if(iPanel instanceof BusiBillPanel){
	        BusiBillPanel djPanel = (BusiBillPanel)iPanel;
	        djPanel.doAddAction(adddata);
	    }
	}

	public void setLinkData(Object[] arg0) {
		IUiPanel iPanel = this.getCurrentPanel();
	    if(iPanel instanceof BusiBillPanel){
	        BusiBillPanel djPanel = (BusiBillPanel)iPanel;
	        djPanel.setLinkData(arg0);
	    }
	}
	public void doMaintainAction(ILinkMaintainData maintaindata)
	{
		IUiPanel iPanel = this.getCurrentPanel();
	    if(iPanel instanceof BusiBillPanel){
	        BusiBillPanel djPanel = (BusiBillPanel)iPanel;
	        djPanel.doMaintainAction(maintaindata);
	    }
	}
    public void postInit() {
    	 IUiPanel iPanel = this.getCurrentPanel();
		    if(iPanel instanceof BusiBillPanel){
		        BusiBillPanel djPanel = (BusiBillPanel)iPanel;
		        djPanel.setM_Node(this.getModuleCode());
		        djPanel.postInit();
		    }
    }
    
    @Override
    public boolean onClosing() {
    	if(msgui != null) {
    		
//    		msgui.querydlg.getChxDealDate().setSelected(false);
    		msgui.querydlg.getChxSendDate().setSelected(false);
//    		msgui.querydlg.onClickDealdate();
    		msgui.querydlg.onClickSenddate();
    		
    		MessageVO[] selVOs = msgui.getSelectedVOs();
    		
    		msgui.onBoRefresh();
    		
    		Vector<MessageVO> nowVOs = msgui.getMsgTableModel().getVOs();
    		for(int i = 0 ; i < nowVOs.size() ; i ++) {
    			for(MessageVO sel : selVOs) {
    				if(sel.getBillNO().equals(nowVOs.get(i).getBillNO())) {
    					msgui.getMsgTableModel().setValueAt(true, i, 2);
    					
    				}
    			}
    		}
    	}
    	return super.onClosing();
    }

}
